<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="packaging.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'accounts.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/indexcss.css">

<script type="text/javascript">
	function check(input,id){				
				var num = input.value ;	
				//isNaN判断num是否为数值，不是返回true，是返回false
				//indexOf('.')查找字符中是否带有‘.’符号，带有就返回‘.’所在的位置，没带有返回-1
				//如2.2这种也算是数值，但我们数量应该是整型数据，因此也不允许不是整型的数据输入
				if(isNaN(num) || num.indexOf('.')!=-1){
					alert("请不要输入非法字符，数量必须是整型数值");
					input.value = "" ;
					input.focus();
					return ;
				}else if(num==""){
					alert("请输入要修改的数量");
					input.focus();
					return ;
				}
				var url = "updatecar.jsp?id="+id+"&num="+num ;
				document.carform.action = url ;
				document.carform.submit();
			}
		</script>



  </head>
  
  <body>
  	<%
			Map<String, CartBean> car = (Map<String, CartBean>) session.getAttribute("car");		
			int numb = 0;
			if (car != null) {
				for (String key : car.keySet()) {
					CartBean cb = car.get(key);
					int num = cb.getNum();
					numb = numb + num;

				}

			}
		%>
		<%
			session.setAttribute("numb", numb);
		%>
  
  
  
  
    <div id="s2">
			<table width="950px" border="0">
				<tr>
					<td width="172" rowspan="2">
						<img src="img/logo.png" width="159" height="85px" />
					</td>
					<td width="395" height="76">
						<p>
							您好!
							<%
						if (session.getAttribute("USER") == null) {
					%>
							<a href="lp.jsp">请登录</a>
												<%
						} else {
					%>

					<a href="buy.jsp"> <%
 	out.print(session.getAttribute("USER")); 	}
 	 
 	if(session.getAttribute("numb")==null){
 	out.print("");} 
 	else{
 	out.print("你的购物车共有"+session.getAttribute("numb")+"件商品");
 	
 	}
 	

 %>
					</a>
						</p>
						<p>
							<span style="color: #FF9966; font-size: 15px"> </span><span
								style="color: #FF9966; font-size: 15px"> 全场购物免配送费! </span>
						</p>
					</td>
					<td width="369" style="color: #FF9966; font-size: 15px">
						<form id="form1" name="form1" method="post" action="check.jsp">

							<input type="text" name="con" id="" size="18" />


							<input type="submit" name="button" id="button" value="搜索"
								style="background: #F6F6F6;" />

						</form>
					</td>
				</tr>
				<tr>
					<td height="15" style="color: #004B91; font-weight: bold">
						我的START SHOES | 礼品卡
					</td>
					<td style="color: #004B91;">
						我的帐户 | 新手上路 | 帮助
					</td>
				</tr>
			</table>
			
		</div>
		
		<div style="padding-top: 0px; margin-top: 0px; border: 1px #DECEA5 solid; width: 940;">
  	 <form name="carform" action="doUpdateCar.jsp"  method="post">
  	 <p style=" font-size:15px; color:#000000；padding-bottom:0px; margin-bottom:0px;padding-left:22px">你所选购的商品</p>
   <table  style="margin-top:0px; padding-top:0px;" align="center" width="940" >
		<tr>
			<td colspan="6" style=" font-size:13px; color:#000000" ></td>
		</tr>
		<tr>
			<th width="100">商品图片</th>
			<th width="300">商品名称</th>
			<th width="100">单价</th>
			<th width="100">数量</th>
			<th width="150">金额</th>
			<th width="100">操作</th>
		</tr>
		<%   
		  
    String pp=(String)session.getAttribute("USER");
    if(pp==null){
    response.sendRedirect("lp.jsp"); 
    }
    
		 car = (Map<String, CartBean>)session.getAttribute("car"); 


		String orderId = "order"+ String.format("%tQ",new Date

()); 
		double total = 0 ;
		String orderMsg = "尊敬的"+pp+"，您好，您的定单信息如下：<br />" ;


		String orderMsg1 = "尊敬的"+pp+"，您好，您的定单信息如下：\n" ;


		if(car!=null){				
			for(String key : car.keySet()){
				CartBean cb = car.get(key);
					bean po = cb.getBen();
					int num = cb.getNum() ;
					total = total +num * po.getImgnewprice();


				orderMsg = orderMsg + po.getImgname()+ "," + num + "件<br />";


				orderMsg1 = orderMsg1 + po.getImgname() + "," + num + "件\n";
%>

		<tr >
			<td align="center"><img src="<%=po.getImgimg() %>"  width="45px"/></td>
			<td align="center" style=" color:#3333FF;font-size:14px;font-weight:200"><%=po.getImgname() %></td>
			<td align="center"><%=po.getImgnewprice() %></td>
			<td align="center"><input name="num" value="<%=num%>" size="5" onblur="check(this,<%=po.getImgid() %>)"/></td>
			<td align="center">¥<%=num * po.getImgnewprice()%></td>
			<td align="center"><a href="Del.jsp?id=<%=po.getImgid() %>" onclick="return del()">删除</a></td>
		</tr>	
		<% 	
			}
		}
  	%>
	</table>	
	</form>
  	
  	
 
			<form action="doaccounts.jsp" method="post" name="orderForm">
				<table border="0" align="center" width="930" >
					<tr>
						<th colspan="2"  >
							
						</th>
					</tr>
					<tr>
						<td  align="right">
				　　　　　订单号：
						</td>
						<td width="650"><%=orderId %><input type="hidden"
								name="orderid" value="<%=orderId %>" />
						</td>


					</tr>
					<tr>
						<td align="right">
							订单信息：
						</td>
						<td><%=orderMsg %><input type="hidden" name=orderMsg
								value="<%=orderMsg1 %>" />
						</td>
					</tr>
					<tr>
						<td align="right">
							总金额：
						</td>
						<td><%=total %><input type="hidden" name="total"
								value="<%=total %>" />
						</td>
					</tr>
					<tr>
						<td align="right">
							发货邮箱地址：
						</td>
						<td>
							<input type="text" size="60" name="address" />
							*(必填：限长50个字符)
						</td>
					</tr>
					<tr>
						<td align="right">
							顾客邮箱地址：
						</td>
						<td>
							<input type="text" size="60" name="email" />
							*(必填：限长50个字符)
						</td>
					</tr>
					<tr>
						<td align="right">
							备注：
						</td>
						<td valign="middle">
							<textarea rows="5" cols="50" name="memo"></textarea>
							(可选：限长500个字符)
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table width="800">
								<tr>
									<td width="300" align="center" valign="middle">
										<input type="submit" value="提交定单" />


									</td>
									<td width="250" align="center" valign="middle">
										<input type="reset" value="  重 填  " />


									</td>
									<td width="250" align="center" valign="middle">
										<input type="button" value="  取 消  "
											onclick="javascript:window.location.href='viewCar.jsp'" />
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</form>
		</div>

	</body>
</html>
